<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function checkAll(){
            //让所有复选框都选中
            //document.getElementsByName("hobby");是根据指定的name属性查询返回多个标签对象集合
            //集合中每个元素都是dom对象
            var hobbies = document.getElementsByName("hobby");
            //checked标识复选框的选中状态，如果选中是true,不选中是false
            //checked这个属性可读可写
            for (let i = 0; i < hobbies.length; i++) {
                hobbies[i].checked = true;
            }
        }

        function checkNo(){
            var hobbies = document.getElementsByName("hobby");
            for (let i = 0; i < hobbies.length; i++) {
                hobbies[i].checked = false;
            }
        }

        function checkReverse(){
            var hobbies = document.getElementsByName("hobby");
            for (let i = 0; i < hobbies.length; i++) {
                // if(hobbies[i].checked){
                //     hobbies[i].checked = false;
                // }else{
                //     hobbies[i].checked = true;
                // }
                hobbies[i].checked = !hobbies[i].checked;
            }
        }
    </script>
</head>
<body>
    兴趣爱好:
    <input type="checkbox" name="hobby" value="cpp">c++
    <input type="checkbox" name="hobby" value="java">java
    <input type="checkbox" name="hobby" value="js">js
    <br>
    <button onclick="checkAll()">全选</button>
    <button onclick="checkNo()">全不选</button>
    <button onclick="checkReverse()">反选</button>
</body>
</html>